var express = require('express');
var router = express.Router();
let db = require("../config/mysql");

router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});
router.post('/search', async(req, res, next)=> {
  let {page,select_can,name,city}  = req.body
  let sql
  if(select_can==""&&name==""&&city==""){
    sql = `select SQL_CALC_FOUND_ROWS * from python_emp LIMIT ${(page - 1) * 10},10;`
  }else{
    sql = `select SQL_CALC_FOUND_ROWS * from python_emp where title like '${name}%' and  province like '${city}%' or select_can = '${select_can}' LIMIT ${(page - 1) * 10},10;`
  }
  console.log(sql)
  let sql2 = `SELECT FOUND_ROWS() as total;`
  let result = await db(sql)
  let result2 = await db(sql2)
  console.log(result2)
  let total = JSON.parse(JSON.stringify(result2))[0].total
 
  res.json({code:1,msg:"查询成功",result:result,total})
});



module.exports = router;
